package com.chat.view;

import com.chat.utils.Expression;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;


import java.io.File;

/*
  该类用于加载聊天界面中的右边消息
 */
public class ChatListRightController {


    public String id;//发送者的id
    public Text nickname;//昵称
    public ImageView touxiang;//头像
    public Text time;//时间
    public TextFlow xinxi;

    public void setTime(String time) {
        this.time.setText(time);
    }

    public void setContectText(String content){
        String[] ee;
        int count=0;
        int begin=0;
        int end = 0;
        for(int i=0;i<content.length();i++){
            if(content.charAt(i)=='['){
                begin=i+1;
                String kk=content.substring(i+1);
                for(int j=0;j< kk.length();j++){
                    if(kk.charAt(j)==']'){
                        end=j+i+1;
                        break;
                    }
                }
                ImageView imageView= Expression.getEmojis(Integer.parseInt(content.substring(begin,end)));
                  xinxi.getChildren().add(imageView);
                i=end;
                begin=0;
                end=0;
                continue;
            }
            Label label=new Label(content.charAt(i)+"");
                  xinxi.getChildren().add(label);
        }
        xinxi.setTextAlignment(TextAlignment.RIGHT);
    }

    public void setTouxiang(String username) {
        File file1=new File("D:/chatproject/client/"+username+".png");
        this.touxiang.setImage(new Image("file:"+file1.getAbsolutePath()));
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setNickname(String nickname) {
        this.nickname.setText(nickname);
    }

}
